package com.steptime.algorithm;

import org.junit.Test;

public class HashDemo {

    static final int hash(Object key) {
        int h;
        return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
    }

    @Test
    public void HashMethodTest(){
        Obj obj = new Obj("tom",12);
        Obj obj2 = new Obj("jim",12);
        System.out.println("this obj's hash code :"+ ((10 - 1) & hash(obj)));
        System.out.println("this obj2's hash code :"+ ((10 - 1) & hash(obj2)));
    }

    class Obj{
        private String name;
        private int age;

        public Obj(String name, int age) {
            this.name = name;
            this.age = age;
        }
    }
}
